# ***meta charset="UTF-8"***
# @Time: 2021/2/2 14:02
# @Author: 邢光强
# @Email： 1062584918@qq.com
# @File： base_page.py
# @Project: crm_project

from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select


class OrganizationPage(BasePage):
    add_user_locator=(By.CSS_SELECTOR,"#user_form > div:nth-child(1) > div > a:nth-child(3)")
    tbody_locator = (By.XPATH,"/html/body/div[5]/div[2]/form/div[2]/table/tbody")
    employee_list_locator = (By.CSS_SELECTOR, "#user_form > div:nth-child(2) > table > tbody")
    # 员工列表行定位器
    tr_locator = (By.TAG_NAME, "tr")
    # 员工列表列定位器
    td_locator = (By.TAG_NAME, "td")
    add_department_locator = (By.ID,"add_department")
    department_name_locator = (By.XPATH,"/html/body/div[8]/div[2]/form/div[1]/div/input")
    parent_department_locator = (By.XPATH,"/html/body/div[8]/div[2]/form/div[2]/div/select")
    department_description_locator = (By.XPATH,"/html/body/div[8]/div[2]/form/div[3]/div/textarea")
    add_dep_qr_locator = (By.XPATH,"/html/body/div[8]/div[3]/div/button[1]/span")
    add_role_locator = (By.ID,"add_role")
    role_name_locator = (By.XPATH,"/html/body/div[9]/div[2]/form/div[1]/div/input")
    ssbm_locator = (By.XPATH,"/html/body/div[9]/div[2]/form/div[2]/div/select")
    parent_role = (By.XPATH,"/html/body/div[9]/div[2]/form/div[3]/div/select")
    role_description_locator = (By.XPATH,"/html/body/div[9]/div[2]/form/div[4]/div/textarea")
    add_role_qr_locator = (By.XPATH,"/html/body/div[9]/div[3]/div/button[1]/span")


    tip_locator = (By.XPATH,"/html/body/div[5]/div[2]")

    def add_user(self):
        self.find_element(self.add_user_locator).click()

    def tip(self):
        tip_element = self.find_element(self.tip_locator)
        return tip_element.text

    def add_department(self):
        self.find_element(self.find_element(self.add_department_locator)).click()

    def input_department(self,department):
        self.find_element(self.add_department_locator).send_keys(department)

    def parent_select(self):
        parent_element = self.find_element(self.parent_department_locator)
        return Select(parent_element)

    def department_description(self,description):
        self.find_element(self.department_description_locator).send_keys(description)

    def add_dep_qr(self):
        self.find_element(self.add_dep_qr_locator).click()

    def add_role(self):
        self.find_element(self.add_user_locator).click()

    def role_name(self,name):
        self.find_element(self.role_name_locator).send_keys(name)

    def ssbm_select(self):
        ssbm_element = self.find_element(self.ssbm_locator)
        return Select(ssbm_element)


